#include <bits/stdc++.h>
#include <unordered_set>

using namespace std;

class Solution {
public:
	bool containsNearbyDuplicate(vector<int>& nums, int k)
	{
		unordered_set<int> set;
		for (int i = 0, len = min(k + 1, (int)size(nums)); i < len; i++) {
			auto [itr, has] = set.emplace(nums[i]);
			if (!has) return true;
		}
		for (int i = k, len = size(nums); i < len; i++) {
			set.erase(nums[i - k]);
			auto [itr, has] = set.emplace(nums[i]);
			if (!has) return true;
		}
		return false;
	}

private:
};

int main()
{
	[[maybe_unused]] Solution solution;
	return 0;
}
